package openapi

import "strings"

func replaceByMap(origin string, replaces map[string]string) string {
	for k, v := range replaces {
		origin = strings.ReplaceAll(origin, k, v)
	}
	return origin
}

func GetSwaggerUI(index int, opt ...Option) string {

	opts := NewOptions(opt...)
	var ui string
	if len(opts.template) > 0 {
		ui = opts.template
	} else {
		id := index % len(swagger_ui)
		ui = swagger_ui[id]
	}

	var content string
	if len(opts.replaceMap) > 0 {
		content = replaceByMap(ui, opts.replaceMap)
	} else {
		content = ui
	}

	return content
}
